package com.example.demo.controller;

import com.example.demo.model.Text;
import com.example.demo.service.VerifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@CrossOrigin(origins = "https://localhost:5173", allowCredentials = "true")
@RestController
@RequestMapping("/api")
public class VerifyController {

    @Autowired
    private VerifyService verifyService;

    /**
     * 表现层：
     *  功能：接收数据，返回结果
     *  参数说明：
     *      text：用户输入内容对象
     *      session：请求会话对象
     *  */
    @RequestMapping("/captcha/check")
    public Boolean captchaCheck(@RequestBody Text text, HttpSession session) {
        // 将数据传递给业务逻辑层进行处理
        String verifyCode = text.getVerifyCode();
        return verifyService.captchaCheck(verifyCode, session);
    }
}
